<template>
  <div class="xtx-steps">
    <div v-for="(item, index) in dymanicItems" :key="index" :class="['xtx-steps-item', { active: index < active }]">
      <div class="step"><span>{{ index + 1 }}</span></div>
      <div class="title">{{ item.title }}</div>
      <div class="desc">{{ item.desc }}</div>
    </div>
  </div>
</template>

<script setup>
import {ref, computed, useSlots} from 'vue';

defineProps({
  active:{
    type: Object,
    default: () =>{ }
  }
})

const slot = useSlots();
// 获取默认插槽的节点
const items = slot.default();
console.log(items)
// 获取所有的动态生成的XtxStepsItem组件节点
const dymanicItems = [];
items.forEach(item => {
  if (item.type.__name === 'xtx-steps-item') {
    dymanicItems.push({
      title: item.props.title,
      desc: item.props.desc
    });
  }
});
console.log(dymanicItems)
// // props
// const active = ref(1);

// computed
const itemsJsx = computed(() => {
  return dymanicItems.map((item, index) => {
    return {
      title: item.props.title,
      desc: item.props.desc,
      index: index
    };
  });
});
</script>

<style scoped>
.xtx-steps {
  display: flex;
  text-align: center;
}

.xtx-steps-item {
  flex: 1;
}

.xtx-steps-item:first-child .step::before {
  display: none;
}

.xtx-steps-item:last-child .step::after {
  display: none;
}

.xtx-steps-item.active .step span {
  border-color: #27BA9B;
  background: #27BA9B;
  color: #fff;
}

.xtx-steps-item.active .step::before,
.xtx-steps-item.active .step::after {
  background: #27BA9B;
}

.step {
  position: relative;
}

.step span {
  width: 48px;
  height: 48px;
  font-size: 28px;
  border: 2px solid #e4e4e4;
  background: #fff;
  border-radius: 50%;
  line-height: 44px;
  color: #ccc;
  display: inline-block;
  position: relative;
  z-index: 1;
}

.step::before,
.step::after {
  content: "";
  position: absolute;
  top: 23px;
  width: 50%;
  height: 2px;
  background: #e4e4e4;
}

.step::before {
  left: 0;
}

.step::after {
  right: 0;
}

.title {
  color: #999;
  padding-top: 12px;
}

.desc {
  font-size: 12px;
  color: #999;
  padding-top: 6px;
}
</style>
